package com.ds.admin.id;

import lombok.RequiredArgsConstructor;
import org.redisson.api.RAtomicLong;
import org.redisson.api.RedissonClient;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * 初始化workerId
 */
@Component
@RequiredArgsConstructor
public class WorkerIdHolder implements CommandLineRunner {

	private final RedissonClient redissonClient;

	public static long WORKER_ID;

	@Override
	public void run(String... args) throws Exception {
		RAtomicLong atomicLong = redissonClient.getAtomicLong("workerId");
		WORKER_ID = atomicLong.incrementAndGet() % 32;
	}

}
